<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
       报修工单-增加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrap.css">
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
<div>

    <div class="main_box">
        <div class="panel-heading">
            <h2>增加报修工单</h2>
        </div>
    </div>

    <form class="layui-form x-center" id="app">
        <h3 style="text-align: left;padding: 10px 15px;">电梯信息</h3>
        <ul style="text-align: left;padding: 10px 15px;">
            <li>使用单位：{{companyname}}</li>
            <li>项目名称：{{projectname}}</li>
            <li>电梯位置：{{address}}</li>
            <li>维保人员：{{person}}</li>
        </ul>

        <div class="layui-form-pane" style="text-align: left;padding: 10px 15px;">


            <h3 style="text-align: left;padding: 10px 15px;">故障信息</h3>
            <div class="layui-form-item">

                <label class="layui-form-label">选择故障</label>
                <div class="layui-input-inline">
                    <div id="demo1" class="xm-select-demo" ></div>
                </div>

            </div>

            <h3 style="text-align: left;padding: 10px 15px;">报修信息</h3>
            <div class="layui-form-item">
                <label class="layui-form-label">报修人员</label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="text" class="layui-input" name="repairperson" id="repairperson" placeholder="报修人员">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话号码</label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="text" class="layui-input" name="tel" id="tel" placeholder="电话号码">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <input  autocomplete="off"  type="text" class="layui-input" name="remark" id="remark" placeholder="备注信息">
                </div>
            </div>

            <div style="text-align: center" class="layui-form-item">
                <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                    保存
                </button>
            </div>
        </div>
    </form>



</div>
</body>

<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script type="text/javascript" src="../../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="../../../js/xm-select.js" type="text/javascript" charset="utf-8"></script>


<script>
    var recordId = getQueryVariable("recordId");
    const vm = new Vue({
        el: "#app",
        data:{
            companyname:null,
            projectname:null,
            address:null,
            person:null,
        },
        computed: {},
        methods: {},
        created() {
            let request = {
                url: 'maintenance/elevator/detail',
                data: {
                    id: recordId,
                    userId:$userId
                },
                method: "POST"
            }
            sendRequest(request, (res) => {
                this.companyname=res.data.elevator.company.name;
                this.projectname=res.data.elevator.project.name;
                this.address=res.data.elevator.address;
                this.person =res.data.userStringList[0];
            });
        },
        mounted() {
            //配置插件目录
            layui.config({
                base: '../../../js/'
                , version: '1.0'
            });
            var demo1 = xmSelect.render({
                el: '#demo1',
                language: 'zn',
                filterable: true,
                toolbar: {
                    show: true,
                },
                autoRow: true,
                data: []
            });

            layui.use([ 'laydate', 'element', 'laypage', 'layer', 'form'],
                function () {

                    $ = layui.jquery;//jquery
                    laydate = layui.laydate;//日期插件
                    lement = layui.element;//面包导航
                    laypage = layui.laypage;//分页
                    var layer = layui.layer;//弹出层
                    var form = layui.form;
                    okLoading.close($);

                    let request5 = {
                        url: '/maintenance/maintainprogram/findByElevatorId',
                        method: 'POST',
                        data: {
                            userId: $userId,
                            elevatorId: recordId
                        }
                    };
                    sendRequest(request5, (res) => {
                        var datas = [];

                        $.each(res.data, function (index, item) {

                            datas.push({
                                name: item.program,
                                value: item.id,
                                selected: false
                            })
                        });

                        demo1.update({
                            data: datas
                        });


                    });




                    //监听审批提交
                    form.on('submit(sub)',
                        function (data) {
                            var selectArr = demo1.getValue();
                            if(selectArr.length==0){
                                layer.msg("请选择故障信息！", {
                                    icon: 5
                                });
                                return false;
                            }else{
                                let form = data.field;

                                var ids = '';
                                $.each(selectArr, function (index, item) {
                                    ids += item.value + ','
                                });

                                form.idString = ids;
                                form.elevatorId =recordId;
                                form.userId=$userId;
                                let request = {
                                    url: 'maintenance/reportRepair/savehou',
                                    data: form,
                                    method: "post",
                                };
                                sendRequest(request, (data) => {
                                    if (data.code === 0) {
                                        layer.alert("操作成功", {
                                                icon: 6
                                            },
                                            function () {
                                                var index = parent.layer.getFrameIndex(window.name);
                                                parent.layer.close(index);
                                                parent.reload();
                                            });
                                    } else {
                                        layer.alert(data.msg, {
                                            icon: 5
                                        })
                                    }
                                });
                                return false;
                            }


                        });
                });
        }

    });

</script>




</html>
